﻿<%@ Page Language="C#" MasterPageFile="~/Layouts/List.Master" AutoEventWireup="true"
    CodeBehind="RoleList.aspx.cs" Inherits="Bingosoft.WebApp.Modules.SecurityConsole.Role.RoleList" %>

<%@ Import Namespace="Bingosoft.Modules.SecurityConsole.Common.Helper" %>

<%@ Import Namespace="Bingosoft.Security" %>
<asp:Content ContentPlaceHolderID="head" ID="idFormTitle" runat="server">
    <!-- title -->
</asp:Content>
<asp:Content ID="idContent" ContentPlaceHolderID="Content" runat="Server">
    <!-- 搜索框 -->
    <div class="search" style="margin-top: 2px;">
        <web:search ID="GridSearch" GridViewId="SmartGridView1" runat="server">
            <SearchConditionTemplate>
                <table cellpadding="0" cellspacing="0" width="95%">
                    <tr>
                        <th>
                            角色名称：
                        </th>
                        <td>
                            <asp:TextBox ID="Name" name="Name" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                </table>
            </SearchConditionTemplate>
        </web:search>
    </div>
    <div class="datalist">
        <!-- 标题头 -->
        <h2 style="height: 30px;">
            角色信息列表
        </h2>
        <!-- 工具栏 -->
        <div class="toolbar" style="height: 30px;">
            <asp:LinkButton runat="server" OnClientClick="return openEditor(this, 'Insert');"
                OnClick="SearchGrid" _visible="ROLE_MANAGE$CREATE_ROLE">
                <span>
                    <img alt="" runat="server" id="img1" src="~/Images/icon_new.gif" style="border: 0px" />新建
                </span>
            </asp:LinkButton>
            <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return delRoles();"
                OnClick="DelRoles" _visible="ROLE_MANAGE$DELETE_ROLE">
                <span>
                    <img id="Img2" alt="" runat="server" src="~/Images/ico_del.gif" style="border: 0px" />删除
                </span>
            </asp:LinkButton>
        </div>
        <div class="datagrid" style="clear: left;">
            <!--------------------------- List Area --------------------------->
            <web:SmartGridView ID="SmartGridView1" runat="server" AutoGenerateColumns="False"
                Width="100%" DataKeyNames="Id" DataSourceID="SmartDataSource1" PageSize="10">
                <Columns>
                    <asp:CheckBoxField DataField="Id" />
                    <asp:BoundField DataField="Name" HeaderText="角色名称" SortExpression="Name" />
                    <asp:BoundField DataField="Type" HeaderText="角色类型" SortExpression="Type" ItemStyle-HorizontalAlign="Center"/>
                    <asp:BoundField DataField="Description" HeaderText="角色描述" SortExpression="Description" />
                    <asp:TemplateField HeaderText="操作">
                        <ItemStyle HorizontalAlign="Center" />
                        <HeaderStyle Wrap="False" HorizontalAlign="Center" />
                        <ItemTemplate>
                            <table width="46px">
                                <tr>
                                    <td style="border: 0px solid #fff;">
                                        <asp:ImageButton ID="ibtnEdit" runat="server" ToolTip="修改" _KeyId='<%#Eval("Id")%>'
                                            ImageUrl="~/images/com/dg_edit.gif" CausesValidation="False" OnClientClick="return openEditor(this, 'Edit');"
                                            OnClick="RefreshGrid" _visible="ROLE_MANAGE$EDIT_ROLE"></asp:ImageButton>
                                    </td>
                                    <td style="border: 0px solid #fff;">
                                        <asp:ImageButton ID="ImageButton3" runat="server" ToolTip="角色继承" _KeyId='<%#Eval("Id")%>' _RoleName='<%#Eval("Name")%>'
                                            ImageUrl="~/Images/ico_ensure_entrust.gif" CausesValidation="False" OnClientClick="return showInheritRoleList(this);"
                                            OnClick="RefreshGrid" _visible="ROLE_MANAGE$INHERIT_ROLE"></asp:ImageButton>
                                    </td>
                                    <td style="border: 0px solid #fff;">
                                        <asp:ImageButton ID="ImageButton2" runat="server" ToolTip="分配权限" _KeyId='<%#Eval("Id")%>'
                                            _RoleName='<%#Eval("Name")%>' ImageUrl="~/Images/ico_assign_privilege.gif" CausesValidation="False"
                                            OnClientClick="return assignPrivilege(this);" _visible="ROLE_MANAGE$ASSIGN_PRIVILEGE">
                                        </asp:ImageButton>
                                    </td>
                                    <td style="border: 0px solid #fff;">
                                        <asp:ImageButton ID="ImageButton1" runat="server" ToolTip="分配用户" _KeyId='<%#Eval("Id")%>' _RoleName='<%#Eval("Name")%>'
                                            ImageUrl="~/images/add_user.png" CausesValidation="False" OnClientClick="return addUsers(this);"
                                            _visible="ROLE_MANAGE$ASSIGN_USER"></asp:ImageButton>
                                    </td>
                                    <td style="border: 0px solid #fff;">
                                        <asp:ImageButton ID="ibtnDelete" runat="server" ToolTip="删除" ImageUrl="~/images/com/dg_del.gif"
                                            _KeyId='<%#Eval("Id")%>' _visible="ROLE_MANAGE$DELETE_ROLE" OnClientClick="return confirm('您确认要删除吗?')"
                                            OnClick="DelRole"></asp:ImageButton>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <CheckBoxSettings Enabled="True" Position="0" />
                <PagerSettings />
                <EditRowStyle HorizontalAlign="Center" />
            </web:SmartGridView>
            <web:SmartSqlDataSource ID="SmartDataSource1" runat="server" SelectCommand="role.role_list" SelectCountCommand="role.role_list.count"
                SelectCommandAutoPageWrap="true" DefaultSortExpression="Id desc">
            </web:SmartSqlDataSource>
        </div>
    </div>
    <script type="text/javascript">
        var Global = {};
        Global.contextPath = '<%= RequestHelper.GetContextPath(Request) %>';

        function openEditor(_this, action) {
            var url = "RoleEdit.aspx";
            var params = { FormViewMode: action };

            if (action == "Insert") {
                params.title = "角色信息新增";
            } else if (action == "Edit") {
                params.Id = _this.attributes["_KeyId"].value;
                params.title = '角色信息编辑';
                params.Random = Math.random();
            }
            var returnValue = showCenterModalDialog(buildUrl(url, params), 530, 330, null);
            return true;
        }

        function addUsers(_this) {
            var params = {};
            params.RoleId = _this.attributes["_KeyId"].value;
            params.RoleName = _this.attributes["_RoleName"].value;
            params.Random = Math.random();
            var url = "RoleUser.aspx";
            showCenterModalDialog(buildUrl(url,params), 700, 400);
            return false;
        }

        function showInheritRoleList(_this) {
            var params = {};
            params.RoleName = _this.attributes["_RoleName"].value;
            params.RoleId = _this.attributes["_KeyId"].value;
            params.Rand = Math.random();
            var url = "RoleInherit.aspx";
            var returnValue = showCenterModalDialog(buildUrl(url, params), 700, 400, null);
            return false;
        }

        function assignPrivilege(_this) {
            var roleId = _this.attributes["_KeyId"].value;
            var roleName = _this.attributes["_RoleName"].value;
            roleName = encodeURIComponent(roleName);
            var url = "PrivilegeAssignment.aspx?roleId=" + roleId + '&roleName=' + roleName; ;
            showCenterModalDialog(url, 700, 600);
            return false;
        }

        function delRoles() {
            var oSmartGridView1 = document.getElementById("<%=SmartGridView1.ClientID%>");
            var sValues = oSmartGridView1.control.getCheckedValues(true);

            if (sValues && sValues.length > 0) {

                return confirm('您确认要删除吗?');
            }

            alert("请您选择要删除的角色！");

            return false;
        }    

    </script>
</asp:Content>
